ARCH 			?= arm
CROSS_COMPILE	?= arm-none-eabi-

TARGET	:= my_target

CC		:= gcc
LD		:= ld
OBJCOPY	:= objcopy
OBJDUMP	:= objdump

LIBPATH	:= -L /lib/arm-none-eabi/lib

INCDIRS	:= utility

SRCDIRS	:= src

INCLUDE	:= $(patsubst %, -I %, $(INCDIRS))

SFILES	:= $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.s))
CFILES	:= $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.c))

SFILENDIR	:= $(notdir $(SFILES))
CFILENDIR	:= $(notdir $(CFILES))

SOBJS	:= $(patsubst %, obj/%, $(SFILENDIR:.s=.o))
COBJS	:= $(patsubst %, obj/%, $(CFILENDIR:.c=.o))

OBJS	:= $(SOBJS) $(COBJS)

VPATH	:= $(SRCDIRS)

$(TARGET) : $(COBJS)
	$(CC) -o $@ $^ $(LIBPATH)

$(SOBJS) : obj/%.o : %.s
	$(CC) -Wall -c -O2 $(INCLUDE) -o $@ $<

$(COBJS) : obj/%.o : %.c
	$(CC) -Wall -c -O2 $(INCLUDE) -o $@ $<

.PHONY:clean

clean:
	rm -rf obj/*.o $(TARGET)

